from django.db import models

# Create your models here.
class City(models.Model):
    name = models.CharField(max_length=100, verbose_name="城市", help_text="请输入城市的名称", unique=True)

    class Meta:
        # 自定义表名
        db_table = "city"
        # 后台显示的模型名称
        verbose_name = "城市信息"
    def __str__(self):
        return self.name


class Room(models.Model):
    name = models.CharField(max_length=100, verbose_name="机房", help_text="请输入机房的名称")
    city = models.ForeignKey(City, related_name="room", on_delete=models.CASCADE)
    class Meta:
        # 自定义表名
        db_table = "room"
        # 后台显示的模型名称
        verbose_name = "城市信息"
    def __str__(self):
        return self.name


class Device(models.Model):
    name = models.CharField(max_length=100, verbose_name="设备名称", help_text="请输入设备的名称")
    ip = models.GenericIPAddressField(verbose_name="设备ip", help_text="请输入设备ip")
    room = models.ForeignKey(Room, related_name="device", on_delete=models.CASCADE)
    class Meta:
        # 自定义表名
        db_table = "device"
        # 后台显示的模型名称
        verbose_name = "城市信息"
    def __str__(self):
        return self.name
    

class DailySummary(models.Model):
    city = models.ForeignKey(City, on_delete=models.CASCADE)
    room = models.ForeignKey(Room, on_delete=models.CASCADE)
    count = models.PositiveIntegerField()
    date = models.DateField()

    class Meta:
        db_table = "dailysummary"
        verbose_name = "每日统计设备信息"
